<!-- /* Description for file.
 *客户管理修改
 *
 * @copyright     Copyright 2008-2010, PHInfo Services Inc. (http://www.phinfoservices.com)
 * @package       ues
 * @subpackage    ues/app/views/companymanages
 * @since         ues
 * @version       V0.0.1
 * @modifiedby    张朋2011年0701
 * @lastmodified  张海杰2011年0812
 -->
<?php
echo $html->css ( 'tab' );
echo $html->css('start/jquery-ui-1.8.2.custom');
echo $javascript->link('jquery-ui-1.8.2.custom.min');
echo $html->css ( 'jquery-validate/css/screen' );
?>

<script type="text/javascript">
	$(function(){
		$(".datepickerSpan :input").datepicker({
			inline: true
		});
		 $('.datepickerSpan :input').datepicker('option', {dateFormat: "yy-mm-dd"});
		 $('.datepickerSpan :input').datepicker( "option", "closeText", 'X' );
		 $("#d1").val("<?php echo substr($editdata['Companymanage']['warranty'],0,10);?>");
	});
</script>

<script type="text/javascript">
$(document).ready(function(){
$("#close").click(function(){
window.close();
});
});
$(document).ready(function(){
	$("#cancel").click(function(){
		$("#CompanymanageAddForm").reset();
		});
	$("#btnajaxAdd").click(function(){		
						$("#CompanymanageAddForm").submit();
					}
					);
	});

//打开用户选择框
$(function()
		{
			$("#allowpersons").click(function(){		
				$(".toolbarStyle").toggle();
			});
			$("#closeallowperson").click(function(){		
				$(".toolbarStyle").toggle();
			});
			$("#closeallowperson").click(function(){		
				$(".toolbarStyle").attr('style').attr('display').val('none');
			});
			
		});
//选择用户提交
$(function()
		{
			$("#addallowperson").click(function(){		
				getDelStr();
				$(".toolbarStyle").toggle();
			});
		});

//用来将选中的用户拼接起来
function getDelStr() {
	var delArr = $(":checkbox:checked");
	if(delArr.length==0)
	{
		alert("请选择用户!");
		return;
	}
	var str = "";
	for(var i=0;i<delArr.length;i++) {
		var del = delArr[i].value;
		str += del;
		str += ",";
	}
	$("#VisitorlistAllowperson").val(str);
}


//行业二级菜单
$(document).ready(function(){
	$("#CompanymanageIndustry1").change(function(){
		var IndustryDroptoplist = $(this).val();
		if(IndustryDroptoplist!="")
		{
			$.post("<?php echo ROOT_WEB_PATH; ?>/industries/industriesQuery/",{
				Industry : $(this).val()
				},
			function(data,textStatus){
					 $("#CompanymanageIndustry2:eq(0)>option").remove();
					 $(data).find("aaa").each(function(){
					 //alert($(this).attr("name"));
					 $("#CompanymanageIndustry2:eq(0)").append("<option></option>");
					 $("#CompanymanageIndustry2:eq(0)>option:last").val($(this).text()).html($(this).text());
				  });
				});
		}
	});
	$("#f1").bind("submit", function() { 
		var value = "";
		if($("#CompanymanageIndustry1 option:selected").text()!="不限")
		value = $("#CompanymanageIndustry1 option:selected").text()+'_';
		if($("#CompanymanageIndustry2 option:selected").text()!="不限"&&$("#CompanymanageIndustry2 option:selected").text()!="--")
		value += $("#CompanymanageIndustry2 option:selected").text();
		$("#CompanymanageIndustry").val(value); });
});

//关键字
$(document).ready(
function()
{

	//添加
	$("#addKeyName").click(
		function()
		{
			var add = $("#keyInput").val();
			var o = $("<option>"+add+"</option>");
			$("#keyOption").append(o);
			var keys ='';
			for(var i = 0; i < $("#keyOption").children().length; i++ )
			{
				keys+=$("#keyOption").children()[i].text + "/";
			}
			$("#keyValue").attr('value',keys);
			//alert($("#keyOption").children().length);
			//alert($("#keyOption").children()[0].text);
		});

$("#f1").bind("submit",
function()
{
	//var add = $("#keyInput").val();
	//var o = $("<option>"+add+"</option>");
	//$("#keyOption").append(o);
	var keys ='';
	for(var i = 0; i < $("#keyOption").children().length; i++ )
	{
		keys+=$("#keyOption").children()[i].text + "/";
	}
	$("#keyValue").attr('value',keys);
	//alert($("#keyOption").children().length);
	//alert($("#keyOption").children()[0].text);
});


	//删除
	$("#delKeyName").click(
		function()
		{
			$("#keyOption option:selected").remove();
		});	
});


//检测重名
$(document).ready(
	function ()
	{
			$("#checkname").click(
			function()
			{
				if($("#CompanymanageShortname").val()!=""){
				$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/sameName/",{
				model : "Companymanage",
				name : $("#CompanymanageShortname").val(),
				id : $("#hiddenid").val()
				},function(data,textStatus){	
				$(data).find("aaa").each(function(){
						if($(this).text()=="false")
						{
							alert("公司简称重名");
						} else {
							alert("可以添加");
						}
				});			
			});
			}
			else{
				alert("请输入公司简称");
			
			}
			});

		//提交
		$(".addsubmit").click(function(){

			if($("#CompanymanageShortname").val()!=""){
			$.post("<?php echo ROOT_WEB_PATH; ?>/companymanages/sameName/",{
			model : "Companymanage",
			name : $("#CompanymanageShortname").val(),
			id : $("#hiddenid").val()
			},function(data,textStatus){	
				$(data).find("aaa").each(function(){
						if($(this).text()=="false")
						{
							alert("公司简称重名");
						} else {
							$("#f1").submit();
						}
				});			
			});
			}
			else{
			alert("请输入公司简称");
			
			}
		});
 
$("#addallowperson").click(
function()
{
	var appstr="";
	$("input:checked").each(function(){
		var name=$(this).val();
		appstr+="/"+name+"/";
	});
	$(".allo").val(appstr);
}
	
);
});


//添加验证
$(document).ready(function() {

//验证是否必填
function test(id)
{
	var srt = "font#" + id;
	var isValidate =  $(srt).text();
	var validate = $.trim(isValidate);
	if(validate == "*"){
		return true;
	} else {
		return false;
	}
}

	$.validator.setDefaults({       
		 submitHandler: function(form) {    
		  form.submit();    
		}       
	});   
			
// validate signup form on keyup and submit
$("#f1").validate({

rules: {
"data[Companymanage][name]" : {
required: test("name"),stringMinLength:0,stringMaxLength:100
},
"data[Companymanage][companyCode]": {
required: test("companyCode"),string:true,minlength:0,maxlength:50
},
"data[Companymanage][tel]": {
required: test("tel"),phone:true
},
"data[Companymanage][industry]": {
required: test("industry"),selectNone:true
},
"data[Companymanage][companyProperty]": {
required: test("companyProperty"),selectNone:true
},
"data[Companymanage][companyType]": {
required: test("companyType"),selectNone:true
},
"data[Companymanage][shortname]": {
required: true,stringMinLength:0,stringMaxLength:100
},
"data[Companymanage][url]": {
required: false,url:true
},
"data[Companymanage][warranty]": {
required: false,dateISO:true
},
"data[Companymanage][keyInput]": {
required: false,stringMinLength:0,stringMaxLength:100 
},
"data[Companymanage][fax]": {
required: false,fax:true
},
"data[Companymanage][product]": {
required: false,stringMinLength:0,stringMaxLength:100
},
"data[Companymanage][location]": {
required: false,stringMinLength:0,stringMaxLength:100
},
"data[Companymanage][postCode]": {
required: false,zipCode:true
},
"data[Companymanage][address]": {
required: false,stringMinLength:0,stringMaxLength:100
},
"data[Companymanage][allowperson]": {
required: true
},
"data[Companymanage][other]": {
required: false,stringMinLength:0,stringMaxLength:255
},
"data[Companymanage][memo]": {
required: false,stringMinLength:0,stringMaxLength:255
}
},
messages: {
},

focusInvalid:false,
onkeyup:false,
errorPlacement:function(error, element){
	error.appendTo(element.parent());
}
});

});


//自动生成客户编号
$(document).ready(
	function()
	{
		$("#creatCode").click(
			function()
			{
			    var user="<?php echo $user; ?>";
				var date="<?php echo $date;?>";
				var thecode = user+date;
				$("#CompanymanageCompanyCode").val(thecode);//将生成的code设置到输入框中
			});
	});
</script>

<style>
.input{float:left}
</style>
<!-- 当前位置-->
<div id="tabmenubar">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td class="tabmenubartitle1"><?php echo  __('YourPosition');//您现在的位置：?></td>
		<td class="tabmenubartitle2"><?php echo __('Customer Managements');//一级目录
										   echo '>';?>
									<?php echo $html->tag('span', __('Edit Customer',true));//当前操作地用span加粗?> 						  
		</td>
	</tr>
</table>
</div>
<!-- 当前位置-->

<!-- 允许查看人弹出 -->
<div class="toolbarStyle" style="display:none">
<iframe style="position:absolute;top:0;left:0;width:100%;height:100%;filter:alpha(opacity=0);z-index:-1;"></iframe>
	<?php 
		foreach ($users as $eachrecord)
		{
			
			$mystring=$editdata['Companymanage']['allowperson'];
			$findme="/".$eachrecord['User']['username']."/";
			if (strstr($mystring, $findme)) {
				echo "<input type='checkbox' checked='checked' class='choose' value='".$eachrecord['User']['username']."'></input>";
			}
			else
			{
				echo "<input type='checkbox' class='choose' value='".$eachrecord['User']['username']."'></input>";
			}
			//echo $form->checkbox($eachrecord['User']['username'], array('value' => $eachrecord['User']['username']));
			echo $eachrecord['User']['username'];
		}
	?>
<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
	<tr>
		<td width="50"></td>
		<td width="100"><?php echo $form->button('确定',array('class'=>'oksubmit','id'=>'addallowperson'));?>  <!-- __('reset', true)取消-->
		<td width="100"><?php echo $form->button('取消',array('class'=>'cancelbutton','id'=>'closeallowperson'));?>  <!-- __('reset', true)取消-->
	</tr>
</table>
</div>
<!-- //允许查看人弹出-->

<div class="tabflex">
	<?php $editid = $editdata['Companymanage']['id']?>
	<input type="hidden" value="<?php echo $editid;?>" id="hiddenid"/>
	<?php echo $form->create('Companymanage',array('action'=>'edit/'.$editid,'type'=> 'post','id'=>'f1'));?>
		<fieldset><legend><?php __('基本信息');?></legend>
		<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left;font-size:12px;">
			<tr>
			<td>
			<?php
				//echo $form->hidden('creater');
				echo $form->hidden('updater');?> </td>
			</tr>
			
			<!--所属行业-->
			<tr>
				<td></td>
				<td><?php __('所属行业');?>:
					<font color="red" id="industry">
						<?php if($fields['industry'] == 1 && $fields['industry'] !=null){echo "*";}?>
					</font>	
				</td>
				<td >
				<?php $options1 = array();
					  $options1[''] = '不限';
					  $flag = false;
					  
					  //将数据库中的行业分解
					  $industryData = $editdata['Companymanage']['industry'];
             		  $industryDataExplode = explode("_",$industryData);
					  
					  foreach($industries as $eachrecord1)
					  {
							$options1[$eachrecord1['Industry']['id']] = $eachrecord1['Industry']['name'];
							if($eachrecord1['Industry']['name'] == $industryDataExplode[0])
							{
								$defaultValue = $eachrecord1['Industry']['id'];
								$flag = true;
							}
					  }
					  if($flag == false){
					  	$defaultValue = '';
					  }
					  echo $form->input('industry1',array('options'=>$options1,'label'=>false,'div'=>false,'class'=>'sitems', 'default' => $defaultValue));		
				?>
				<?php 
					  $options5 = array();
					  $options5[''] = '不限';
					  $flag = false;
					  
					  
					  //将数据库中的行业分解
					  $industryData = $editdata['Companymanage']['industry'];
             		  $industryDataExplode = explode("_",$industryData);
					  
             		  if(count($industryDataExplode) > 1)
             		  {
             		  	  foreach($thisSecond as $eachrecord1)
             		  	  {
             		  	  		$options5[$eachrecord1['Industry']['id']] = $eachrecord1['Industry']['name'];
             		  	  		if($industryDataExplode[1] == $eachrecord1['Industry']['name'])
             		  	  		{
             		  	  			
             		  	  			$defaultValue = $eachrecord1['Industry']['id'];
             		  	  			$flag = true;
             		  	  		}
             		  	  }
             		  }

					  if($flag == false){
					  	$defaultValue = '';
					  }
				echo $form->input('industry2',array('options'=>$options5,'label'=>false,'div'=>false,'class'=>'sitems','default'=>$defaultValue));		
				?>
				<?php 
					echo $form->hidden('industry');
				?>
				</td>
				<td></td>
				<td><?php __('公司简称');?>:<font color=red>*</font></td>
				<td>
				<?php echo $form->input('shortname',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['shortname']));?>
				<?php echo "<input type='button' value='检测重复' class='btn4' id='checkname' ></input>"?>
				</td>

			</tr>
			<!--//所属行业-->
		
			<!--企业性质-->
			<tr>
				<td></td>
				<td><?php __('企业性质');?>:
					<font color="red" id="companyProperty">
						<?php if($fields['companyProperty'] == 1 && $fields['companyProperty'] !=null){echo "*";}?>
					</font>				
				</td>
				<td colspan="1">
				<?php 
					  $options2[''] = '不限';
					  $flag = false;
					  foreach($firmattributes as $eachrecord2)
					  {
					  		$options2[$eachrecord2['Firmattribute']['name']] = $eachrecord2['Firmattribute']['name'];
							if($eachrecord2['Firmattribute']['name'] == $editdata['Companymanage']['companyProperty'])
							{
								$defaultValue = $eachrecord2['Firmattribute']['name'];
								$flag = true;
							}								
					  }
					  if($flag == false){
					  	$defaultValue = '';
					  }
							
					echo $form->input('companyProperty',array('options'=>$options2,'label'=>false,'div'=>false,'class'=>'TextBoxE1','default' =>$defaultValue));		
				?>
				</td>
				<td></td>
				<td><?php __('企业类型');?>:
					<font color="red" id="companyType">
						<?php if($fields['companyType'] == 1 && $fields['companyType'] !=null){echo "*";}?>
					</font>				
				</td>
				<td colspan="1">
				<?php $options3 = array();
					  $options3[''] = '不限';
					  $flag = false;
							foreach($companyTypes as $eachrecord3)
							{
								$options3[$eachrecord3['Customertype']['name']] = $eachrecord3['Customertype']['name'];
								if($eachrecord3['Customertype']['name'] == $editdata['Companymanage']['companyType'])
								{
									$defaultValue = $eachrecord3['Customertype']['name'];
									$flag = true;
								}	
							}
					  if($flag == false){
					  	$defaultValue = '';
					  }
					  echo $form->input('companyType',array('empty' =>'不限','options'=>$options3,'label'=>false,'div'=>false,'class'=>'TextBoxE1','default' => $defaultValue));		
				?>
				</td>
			</tr>
			<!--//企业性质-->
			
			<!--公司名称、客户编号-->
			<tr>
				<td  width="5%"></td>
				<td  width="10%"><?php __('公司名称');?>:
					<font color="red" id="name">
						<?php echo "*";?>
					</font>				
				</td>
				<td  width="35%">
				<?php echo $form->input('name',array('class' => 'TextBoxE1','label'=>false,'id'=>'name','default'=>$editdata['Companymanage']['name']));?>
				</td>
				<td  width="5%"></td>
				<td  width="10%"><?php __('客户编号');?>:
					<font color="red" id="companyCode">
						<?php if($fields['companyCode'] == 1 && $fields['companyCode'] !=null){echo "*";}?>
					</font>				
				</td>
				<td  width="35%">
				<?php echo $form->input('companyCode',array('class' => 'TextBoxE1','readOnly'=>true,'label'=>false,'default'=>$editdata['Companymanage']['companyCode']));?>
					<?php echo "<input type='button' class='btn4' value='自动生成' id='creatCode' ></input>" ;
					?>
				</td>
			</tr>
			<!--//公司名称、客户编号-->
			<!--公司网址、联系电话-->
			<tr>
				<td></td>
				<td><?php __('公司网址');?>:</td>
				<td colspan="1">
				<?php echo $form->input('url',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['url']));?>
				</td>
				<td></td>
				<td><?php __('联系电话');?>:
					<font color="red" id="tel">
						<?php if($fields['tel'] == 1 && $fields['tel'] !=null){echo "*";}?>
					</font>				
				</td>
				<td colspan="1">
				<?php echo $form->input('tel',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['tel']));?>
				</td>
			</tr>
			<!--//公司网址、联系电话-->
			
			<!--客户传真、公司产品-->
			<tr>
				<td ></td>
				<td><?php __('客户传真');?>:</td>
				<td colspan="1">
				<?php echo $form->input('fax',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['fax']));?>
				</td>
				<td></td>
				<td><?php __('公司产品');?>:</td>
				<td colspan="1">
				<?php echo $form->input('product',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['product']));?>
				</td>
			</tr>
			<!--//客户传真、公司产品-->
			
			<!--地区、客户状态-->
			<tr>
				<td></td>
				<td><?php __('地区');?>:</td>
				<td colspan="1">
				<?php echo $form->input('location',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['location']));?>
				</td>
				<td></td>
				<td><?php __('客户状态');?>:</td>
				<td colspan="1">
				<?php $options4 = array();
					  $options4[''] = '不限';
					  $flag = false;
							foreach($customerStatues as $eachrecord3)
							{
								$options4[$eachrecord3['Customerstate']['customerStateName']] = $eachrecord3['Customerstate']['customerStateName'];
								if($eachrecord3['Customerstate']['customerStateName'] == $editdata['Companymanage']['customerStatues'])
								{
									$defaultValue = $eachrecord3['Customerstate']['customerStateName'];
									$flag = true;
								}	
							}
					  if($flag == false){
					  	$defaultValue = '';
					  }
					 echo $form->input('customerStatues',array('empty' =>'不限','options'=>$options4,'label'=>false,'div'=>false,'class'=>'TextBoxE1','default' => $defaultValue));		
				  
				?>
				</td>
			</tr>
			<!--//地区、客户状态-->
			
			<!--客户地址、邮政编码-->
			<tr>
				<td></td>
				<td><?php __('客户地址');?>:</td>
				<td colspan="1">
				<?php echo $form->input('address',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['address']));?>
				</td>
				<td></td>
				<td><?php __('邮政编码');?>:</td>
				<td colspan="1">
				<?php echo $form->input('postCode',array('class' => 'TextBoxE1','label'=>false,'default'=>$editdata['Companymanage']['postCode']));?>
				</td>
			</tr>
			<!--//客户地址、邮政编码-->
			
			<!--允许查看人、保证期-->
			<tr>
				<td></td>
				<td><?php __('允许查看人');?>:</td>
				<td>
				<?php 	
					echo $form->input('allowperson',array('label'=>false, 'class'=>'allo',"readonly"=>"true",'default'=>$editdata['Companymanage']['allowperson']));
				?> 
				<?php 	
					echo $form->button('允许人',array('class'=>'oksubmit','id'=>'allowpersons'));
				?> 
				</td>
				<td></td>
				<td ><?php __('保证期');?>:</td>
				<td colspan="1">
					<span class="datepickerSpan">
							<?php echo $form->input('warranty',array('label'=>false,'id'=>'d1', 'type'=>'text',"readonly"=>"true",'default'=>substr($editdata['Companymanage']['warranty'],0,10)));?>
					</span>
				</td>
			</tr>
			<!--//允许查看人、保证期-->
			</table>
			</fieldset>
			
			<fieldset><legend><?php __('其他信息/备注');?></legend>
			<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: left">
			<tr>
				<td ></td>
				<td ><?php __('其他信息');?>:</td>
				<td colspan="2">
					<?php echo $form->input('other',array('class' => 'TextBoxH','label'=>false,'default'=>$editdata['Companymanage']['other']));?>
				</td>
			</tr>
			<tr>
				<td ></td>
				<td><?php __('客户备注');?>:</td>
				<td colspan="2">
					<?php echo $form->input('memo',array('class' => 'TextBoxH','label'=>false,'default'=>$editdata['Companymanage']['memo']));?>
				</td>
			</tr>
			<tr>
				<td></td>
				<td><?php __('公司名称关键字');?>:</td>
				<td >
					<?php echo $form->input('keyInput',array('class' => 'TextBoxH','id'=>'keyInput','label'=>false));?>
					<?php echo $form->input('nameKeyWords',array('class' => 'TextBoxH','id'=>'keyValue','label'=>false,'type'=>'hidden', 'value'=>''));?>
				</td><td>
				<?php echo "<input type='button' class='newsubmit' value='添加' id='addKeyName'"?></td>
			</tr>
			<tr>
				<td width="5%"></td>
				<td width="10%"></td>
				<td width="30%">
					<?php 
					$toplistOptions = array();
				    $nameKeyWords = $editdata['Companymanage']['nameKeyWords'];
             		$toplistOptions = explode("/",$nameKeyWords);
             		$length = count($toplistOptions);
             		unset($toplistOptions[$length - 1]);
             		
					echo $form->input('',array('options'=>$toplistOptions,'label'=>false,'id'=>'keyOption','div'=>false,'class'=>'TextBoxH','size'=>5));?>
				</td>
				<td><?php echo "<input type='button' class='deletebutton' value='删除' id='delKeyName'"?></td>
			</tr>
		</table>
		</fieldset>
		
		<table width="100%" cellspacing="0" cellpadding="0" border="0" style="text-align: center">
			<tr>
				<td width="50"></td>
				<td width="100">
					<?php 
						echo "<input type='button' class='addsubmit' value='确定'/>";?>
				</td>
				<td width="100">		
					<?php	echo "<input type='reset' class='resetsubmit' value='重置'/>";			
					?>
				</td>
				<td width="100">		
					<?php	echo "<input type='button' class='cancelbutton' id='close' value='关闭'/>";			
					?>
				</td>
			</tr>
		</table>
			
	<?php echo $form->end();?>
</div>
 